<script language="javascript" type="text/javascript">
    $(window).scroll(
    function()
    {
        scrollTop = $(window).scrollTop();
        docHeight = getDocHeight();
        winHeight = getWinHeight();
        scrolltop20 = Math.round((getDocHeight() - getWinHeight())*0.9);
        result = getDocHeight() - getWinHeight();
		
        console.log('Top Scroll: '+ scrollTop +' || Win Height: '+ winHeight +' || Doc Height: '+ docHeight+' || scrolltop20: '+scrolltop20+' || result :'+ result );
	
        if($(window).scrollTop() >= scrolltop20)
        {
            if(killScroll == false) 
            {
                killScroll = true;
				
                $('#loading').show();
                $('#loadding-text').show();			
                $('#loading').html('<img src="images/loading.gif" alt="" width="150" height="13" />');

                if($("li:last").data('ctype') == 'webboardSearch')
                {
                    webboardSearch('webboardSearch', $("li:last").data('wordsearch'), $("li:last").data('webboardtype'));
                }
                setTimeout(function(){killScroll = false},500);	
            }
        }
    }
); 
</script>

<div data-role="page" id="webboardSearch">
    <div data-role="header">
        <h1>ผลการค้นหา</h1>
        <a rel="external" id="link_web" href="?q=webboard" data-icon="back" data-iconpos="right">กลับ</a>        
    </div><!-- /header -->
    <div data-role="content">	
        <ul data-role="listview">
            <?php
            //	id	post_title	post_details	type -- webboard
            $sql = 'SELECT * FROM webboard WHERE post_title like "%' . $db->antihack($_GET['webboard_search']) . '%" ';
            if($_GET['webboard_type'] != 0)
            {
                $sql .='AND type = ' . $db->antihack($_GET['webboard_type']) . ' ';
            }
            $sql .= 'ORDER BY id DESC LIMIT 20 ';
            $res = $db->select_query($sql);
            $numRow = $db->rows($res);
            if($numRow > 0)
            {
                while($arr = $db->fetch($res))
                {
                    $countReply = $db->num_rows('webboard_reply', 'reply_id', 'post_id = ' . $arr['id'] . '');
                    ?>
                    <li data-ctype="webboardSearch" data-wordsearch='<?php echo $_GET['webboard_search']; ?>' data-webboardtype='<?php echo $_GET['webboard_type']; ?>' id="webboard_<?php echo $arr['id']; ?>" last_id="<?php echo $arr['id']; ?>">
                        <a rel="external" href="?q=webboardDetail&wId=<?php echo $arr['id']; ?>">
                            <img src="<?php echo $arr['tn_part']; ?>" alt="" width="80" height="80" />
                            <h3><?php echo $arr['post_title']; ?></h3>
                            <p><?php echo 'โดบ : ' . $arr['cr_by'] . ' วันที่ : ' . $arr['cr_date']; ?></p>
                            <span class="ui-li-count ui-btn-up-c ui-btn-corner-all"><?php echo $countReply; ?></span>
                        </a> 
                    </li>
                    <?php
                }
            }
            else
            {
                ?>
                <li>
                    <h3>--  ไม่พบข้อมูลในระบบ --</h3>
                </li>
                <?php
            }
            ?>
        </ul>
        <?php
        if($numRow != 0)
        {
            ?>
            <div id="loadding-text" style="clear:both;">&nbsp;&nbsp;</div>
            <div id="loading" align="center"><img src="images/loading.gif" alt="" width="150" height="13" /></div>
            <?php
        }
        ?>       
    </div><!-- /content -->

    <div data-role="footer" >
        <h4>Version 1.0 Beta</h4>
        <a id="link_web" href="http://www.mocyc.com" data-icon="refresh" data-iconpos="right" class="ui-btn-right">แบบปกติ</a>

    </div><!-- /footer -->
</div><!-- /page -->
</body>
</html>